package com.tjsinfo.tjsoa.useseal.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal;

/**
 * A data access object (DAO) providing persistence and search support for
 * TUseSealGi entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.tjsinfo.tjsoa.useseal.dao.TUseSealSeal
 * @author MyEclipse Persistence Tools
 */

public class TUseSealSealDAO extends HibernateDaoSupport implements ITUseSealSealDAO {
	private static final Log log = LogFactory.getLog(TUseSealSealDAO.class);

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#save(com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal)
	 */
	public void save(TUseSealSeal transientInstance) {
		log.debug("saving TUseSealSeal instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#delete(com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal)
	 */
	public void delete(TUseSealSeal persistentInstance) {
		log.debug("deleting TUseSealSeal instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#findById(java.lang.String)
	 */
	public TUseSealSeal findById(java.lang.String id) {
		log.debug("getting TUseSealSeal instance with id: " + id);
		try {
			TUseSealSeal instance = (TUseSealSeal) getHibernateTemplate().get(
					"com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#findByExample(com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal)
	 */
	public List findByExample(TUseSealSeal instance) {
		log.debug("finding TUseSealSeal instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TUseSealSeal instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TUseSealSeal as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all TUseSealSeal instances");
		try {
			String queryString = "from TUseSealSeal";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#merge(com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal)
	 */
	public TUseSealSeal merge(TUseSealSeal detachedInstance) {
		log.debug("merging TUseSealSeal instance");
		try {
			TUseSealSeal result = (TUseSealSeal) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#attachDirty(com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal)
	 */
	public void attachDirty(TUseSealSeal instance) {
		log.debug("attaching dirty TUseSealSeal instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO#attachClean(com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal)
	 */
	public void attachClean(TUseSealSeal instance) {
		log.debug("attaching clean TUseSealSeal instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
	
	public void update(TUseSealSeal transientInstance) {
		log.debug("updating TUseSealSeal instance");
		try {
			getHibernateTemplate().update(transientInstance);
			log.debug("update successful");
		} catch (RuntimeException re) {
			log.error("update failed", re);
			throw re;
		}
	}		
	
	public void delete(String id) {
		log.debug("deleting TUseSealSeal instance");
		try {
			TUseSealSeal tusso = (TUseSealSeal)this.getHibernateTemplate().load(TUseSealSeal.class, id);
			getHibernateTemplate().delete(tusso);
			log.debug("Delete successful");
		} catch (RuntimeException re) {
			log.error("Delete failed", re);
			throw re;
		}
	}	
	
	public String saveId(TUseSealSeal transientInstance) {
		log.debug("saving TUseSealSeal instance");
		try {
			return (String)getHibernateTemplate().save(transientInstance);
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}	
	
	public static ITUseSealSealDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ITUseSealSealDAO) ctx.getBean("TUseSealSealDAO");
	}
}